/*
 * @Author: szx
 * @Date: 2022-03-03 14:26:46
 * @LastEditTime: 2022-03-03 14:33:08
 * @Description:
 * @FilePath: \leetcode\200-299\257\257_2.js
 */
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function (root) {
    const res = [];
    const dfs = function (root, path) {
        if (!root.left && !root.right) {
            path.push(root.val);
            res.push(path.join('->'));
            path.pop();
            return;
        }
        path.push(root.val);
        root.left && dfs(root.left, path);
        root.right && dfs(root.right, path);
        path.pop();
    };
    dfs(root, []);
    return res;
};
